package com.qf.service.impl;

import com.qf.exception.CustomerException;
import com.qf.mapper.CostMapper;
import com.qf.pojo.Cost;
import com.qf.service.CostService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zdl
 * @date 2025/2/15
 */
@Service
public class CostServiceImpl implements CostService {
    @Resource
    private CostMapper costMapper;
    @Override
    public List<Cost> findAllCost() {
        return costMapper.selectAllCost();
    }

    @Override
    public int addCost(Cost cost) {
        return costMapper.insertCost(cost);
    }

    @Override
    public int delCostByCid(int cid) {
        Cost cost = costMapper.selectCostByCid(cid);
        if (cost == null){
            throw  new CustomerException("80001","该数据不存在");
        }
        return costMapper.delCostByCid(cid);
    }

    @Override
    public int updateCostByCost(Cost cost) {
        return costMapper.updateCost(cost);
    }
}
